﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;


namespace CoppyDatabase.Commons
{
   public class Common
    {
        public static string ParseString(object obj)
        {
            try
            {
                if (IsNullOrEmpty(obj))
                    return "";
                return obj.ToString();
            }
            catch (Exception ex)
            {
                return "";
                throw ex;
            }
        }
        public static bool IsNullOrEmpty(object obj)
        {
            try
            {
                if (obj == null)
                    return true;
                if (obj.ToString().Trim().Equals(""))
                    return true;
                return false;
            }
            catch (Exception ex)
            {
                return false;
                throw ex;
            }
        }
        public static int ParseInt(object obj)
        {
            try
            {
                if (IsNullOrEmpty(obj))
                    return 0;
                return int.Parse(obj.ToString());
            }
            catch (Exception ex)
            {
                return 0;
                throw ex;
            }
        }
        public static decimal ParseDecimal(object obj)
        {
            try
            {
                if (IsNullOrEmpty(obj))
                    return 0;
                return decimal.Parse(obj.ToString());
            }
            catch (Exception ex)
            {
                return 0;
                throw ex;
            }
        }
        public static string GetPath_MySqlConnection()
        {
            System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
            string imagePath = Path.GetFullPath(System.AppDomain.CurrentDomain.BaseDirectory.ToString() + "\\strConnection\\MySql_Connection.txt");
            //(string)(configurationAppSettings.GetValue("imagePath", typeof(string))));
            return imagePath;
        }

        public static Boolean CheckIsNumber(string str)
        {
            
            double Num;
            bool isNum = double.TryParse(str, out Num);
            if (isNum)
                return true;
            else
                return false;
        }
        public static Boolean CheckIsDateTime(string dateTime)
        { 
        DateTime temp;
        if(DateTime.TryParse(dateTime, out temp))
         return true;
        else
            return false;
        }
        public static string GetPath_SqlConnection()
        {
            System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
            string imagePath = Path.GetFullPath(System.AppDomain.CurrentDomain.BaseDirectory.ToString() + "\\strConnection\\Sql_Connection.txt");
            //(string)(configurationAppSettings.GetValue("imagePath", typeof(string))));
            return imagePath;
        }

        public static void WriterData(string Path, string Data)
        {
            System.IO.File.WriteAllText(Path, Data);
        }
        
    }

   
}
